package objects;

import java.util.ArrayList;
import java.util.List;

public abstract class Player  implements Comparable<Player>
{
	private int playerId;
	private int order;
	private String playerName;
	private String playerType;
	private Character character;
	private List<Card> cardsList;
	private int roomNumber;
	private boolean isInTheGame; 
	private String reason;
	private boolean isOccupied;
	
	public Player(int playerId, String playerName, Character playerCharacter, String playerType) 
	{
			this.playerName = playerName;
			this.playerType = playerType;
			this.playerId = playerId;
			this.character = playerCharacter;
			isOccupied = false;
			isInTheGame = true;
			reason = "";
	}

	public Player(int playerId, String playerName, Character playerCharacter, String playerType, int nOrder) 
	{
			this.playerName = playerName;
			this.playerType = playerType;
			this.playerId = playerId;
			this.character = playerCharacter;
			this.order = nOrder;
			isOccupied = false;
			isInTheGame = true;
			reason = "";
	}
	/**
	 * The method shows the cards of the player
	 * @return
	 */
	public String showMyCards()
	{
		StringBuilder builder = new StringBuilder();
		
		for (Card card : cardsList) {
			builder.append(card.getName());
			builder.append(", ");
		}
		
		return builder.toString();
	}
	
	public List<String> getWeapons()
	{
		List<String> weapons = new ArrayList<String>();
		
		for (Card card : cardsList) {
			if (card.getType().equals(CardType.WEAPON))
			{
				weapons.add(card.getName());
			}
		}
		
		return weapons;
	}
	
	public List<String> getCharacters()
	{
		List<String> characters = new ArrayList<String>();
		
		for (Card card : cardsList) {
			if (card.getType().equals(CardType.CHARACTER))
			{
				characters.add(card.getName());
			}
		}
		
		return characters;
	}
	
	public List<String> getRooms()
	{
		List<String> rooms = new ArrayList<String>();
		
		for (Card card : cardsList) {
			if (card.getType().equals(CardType.ROOM))
			{
				rooms.add(card.getName());
			}
		}
		
		return rooms;
	}
	
	public String getPlayerName() {
		return playerName;
	}

	public void setPlayerName(String playerName) {
		this.playerName = playerName;
	}

	public int getPlayerId() {
		return playerId;
	}

	public void setPlayerId(int playerId) {
		this.playerId = playerId;
	}

	public List<Card> getCardsList() {
		return cardsList;
	}

	public void setCardsList(List<Card> cardsList) {
		this.cardsList = cardsList;
	}

	public Character getCharacter() {
		return character;
	}

	public void setCharacter(Character character) {
		this.character = character;
	}
	
	/**
	 * The method adds another card to the list of cards player holds 
	 */
	public void addCard(Card card)
	{
		if (cardsList == null)
		{
			cardsList = new ArrayList<Card>();
		}
		
		cardsList.add(card);
	}
	
	@Override
	public String toString()
	{
		return "Player number " + playerId + "." + playerName + "-" + character;
	}

	public int getRoomNumber() {
		return roomNumber;
	}

	public void setRoomNumber(int roomNumber) {
		this.roomNumber = roomNumber;
	}

	public boolean isInTheGame() {
		return isInTheGame;
	}

	public void setInTheGame(boolean isInTheGame) {
		this.isInTheGame = isInTheGame;
	}

	@Override
	public boolean equals(Object otherPlayer)
	{
		if (otherPlayer instanceof Player)
		{
			return (((Player) otherPlayer).getPlayerId() == this.getPlayerId());
		}

		return false;
	}

	@Override
	public int compareTo(Player o) {
		if (order > o.order)
		{
			return 1;
		}
		else 
		{
			return -1;
		}
	}
	public int getOrder() {
		return order;
	}
	public void setOrder(int order) {
		this.order = order;
	}

	public String getReason() {
		return reason;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	public String getType() {
		return playerType;
	}

	public void setType(String playerType) {
		this.playerType = playerType;
	}

	public boolean isOccupied() {
		return isOccupied;
	}

	public void setOccupied(boolean isOccupied) {
		this.isOccupied = isOccupied;
	}
}
